/*
Auhtor      : Pratibh Prakash
Company     : Fujitsu America
Created Date: 30 Sep-2009
Modified    : 
Description : Test class for preventAccountCreateTrigger 
*/
@isTest
private class preventAccountCreateTriggerTest {
    static testMethod void testAccountCreateTrigger() {
		 List<Account> accForInsert = new List<Account>();
		 for(Integer i=0; i<200; i++){
		 	Account testAccount = new Account(Name = 'Test Account'+String.valueOf(i));
		 	accForInsert.add(testAccount);
		 }  
		 Set<String> adminProfiles = new Set<String>();
		 adminProfiles.addAll(Label.IM_Admin_Profiles.split(';'));
		 
		 List<User> nonAdminUser = new List<USer>([Select Id from User where IsActive = true and Profile.Name not in: adminProfiles ]);
		 List<User> AdminUser = new List<USer>([Select Id from User where IsActive = true and Profile.Name in: adminProfiles ]);
		 
		 //Inserting Account for non-Admin Profiles
		 if(nonAdminUser.size()>0){
		 	System.runAs(nonAdminUser[0]){
		 		try{
		 			insert accForInsert;
		 		}
		 		catch(Exception ex){
		 			System.assert(ex.getMessage().contains('Insufficient Privileges to create new Account'));
		 		}
		 	}
		 }    
		 
		 //Inserting Account for Admin Profiles
		 accForInsert.clear();
		 for(Integer i=0; i<200; i++){
		 	Account testAccount = new Account(Name = 'Test Account'+String.valueOf(i));
		 	accForInsert.add(testAccount);
		 } 
		 if(AdminUser.size()>0){
		 	System.runAs(AdminUser[0]){
		 		insert accForInsert;
		 	}
		 }
    }
}